package com.ny.zmb.openapi.jh.controller;

import com.alibaba.fastjson.JSONObject;
import com.ny.zmb.openapi.controller.entity.Result;
import com.ny.zmb.openapi.jh.from.ProductSearchFrom;
import com.ny.zmb.openapi.jh.service.JHProductService;
import com.ny.zmb.openapi.jh.vo.JHProductVo;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/jh/product")
@RestController
@CrossOrigin
public class JHProductController {

    /**
     * 获取商品列表
     * @param pageNo
     * @param prodId
     * @return
     */
    @GetMapping("list")
    public Result list(Integer pageNo,Long prodId){
        List<Integer> productList = JHProductService.getProductList(pageNo,prodId);
        return Result.ok(productList);
    }

    /**
     * 商品详情
     * @param prodId
     * @return
     */
    @GetMapping("detail")
    public Result detail(Integer prodId){
        JSONObject detail = JHProductService.getProductDetail(prodId);
        JHProductVo jhProductVo = detail.toJavaObject(JHProductVo.class);
        return Result.ok(jhProductVo);
    }

    /**
     * 商品状态 和价格
     * status 0 是可售，非0 不可售
     * @param prodIds
     * @return
     */
    @GetMapping("price")
    public Result price(Integer prodIds){
        List<JSONObject> productPrice = JHProductService.getProductPrice(prodIds);
        return Result.ok(productPrice);
    }

    /**
     * 搜索商品列表
     * @param from
     * @return
     */
    @GetMapping("search")
    public Result search(@RequestBody ProductSearchFrom from){
        JSONObject productSearch = JHProductService.getProductSearch(from);
        return Result.ok(productSearch);
    }
}
